import { _decorator, Component, Node, v3, tween, view, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('BCViewBase')
export class BCViewBase extends Component {
	protected m_viewClosedCallback: ()=>void = null;
	set _viewClosedCallback(cb: () => void){
		this.m_viewClosedCallback = cb;
	}

	_resetView(){
		const width = view.getVisibleSize().width;
		this.node.getComponent(UITransform).contentSize = view.getVisibleSize();
		this.node.position = v3(width, 0);
	}

	_showView(option?: any) {
		tween(this.node).to(0.2, { position: v3(0, 0) }).start();
	}

	async _closeView(): Promise<void>{
		const width = view.getVisibleSize().width;
		return new Promise(res=>{
			tween(this.node).by(0.2, { position: v3(width, 0) }).call(() => {
				this.m_viewClosedCallback && this.m_viewClosedCallback();
				res();
			}).start();
		});
	}

	onDestroy() {
		this.m_viewClosedCallback && this.m_viewClosedCallback();
	}
}

